package com.example.game.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author CHENTAIWEN
 * @create 2023/2/21 9:10
 */
@RestController
@RequestMapping("/Genshen")
public class GenshenController {

    public static void main(String[] args) {

        ClassPathResource classPathResource = new ClassPathResource("org/role");
        StringBuilder sb = new StringBuilder();
        InputStreamReader bufferedInputStream = null;
        try {
            bufferedInputStream = new InputStreamReader(classPathResource.getInputStream(), StandardCharsets.UTF_8);
        } catch (IOException e) {
            e.printStackTrace();
        }
        int tmp = 0;
        while (true) {
            try {
                if (!((tmp = bufferedInputStream.read()) != -1)) break;
            } catch (IOException e) {
                e.printStackTrace();
            }
            sb.append((char) tmp);
        }
        String json = sb.toString();
        Map<String, Object> map = JSON.parseObject(json, HashMap.class);
        List roleList = JSON.parseObject(map.get("role").toString(), List.class);
        List armsList = JSON.parseObject(map.get("arms").toString(), List.class);
        while (true) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("带");
            stringBuilder.append(armsList.get((int) (Math.random() * 35)));
            stringBuilder.append("的");
            stringBuilder.append(roleList.get((int) (Math.random() * 66)));
            System.out.println(stringBuilder);
        }
    }
}
